/*
 *  * Copyright (C) 2021 Huawei Device Co., Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.example.smileyrating.slice;

import com.example.smileyrating.ResourceTable;
import com.hsalf.smileyrating.SmileyRating;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;

public class SmileyRating2Slice extends AbilitySlice {

    private SmileyRating mSmileyRating;

    private Text text_status;

    private Button btn_reset;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer rootLayout = (ComponentContainer) LayoutScatter.getInstance(getContext())
            .parse(ResourceTable.Layout_smiley_rating2, null, false);
        mSmileyRating = (SmileyRating) rootLayout.findComponentById(ResourceTable.Id_smiley);
        text_status = (Text) rootLayout.findComponentById(ResourceTable.Id_status);
        btn_reset = (Button) rootLayout.findComponentById(ResourceTable.Id_reset);

        mSmileyRating.setSmileySelectedListener(new SmileyRating.OnSmileySelectedListener() {
            @Override
            public void onSmileySelected(SmileyRating.Type type) {
                text_status.setText(type.toString());
            }
        });

        mSmileyRating.setTitle(SmileyRating.Type.GREAT, "Awesome");
        mSmileyRating.setFaceColor(SmileyRating.Type.GREAT, Color.BLUE.getValue());
        mSmileyRating.setFaceBackgroundColor(SmileyRating.Type.GREAT, Color.RED.getValue());

        btn_reset.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                mSmileyRating.setRating(1);
                text_status.setText(SmileyRating.Type.TERRIBLE.toString());
            }
        });

        super.setUIContent(rootLayout);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
